package game;

public class Earning {

	private int repeatRound = 1;
	
	/*
	 Wares:
	    0: food
	    1: gold
	    2: lumber
	    3: stone
	    4: iron
	*/
	
	private int[] constantWares = {0,0,0,0,0};
	private int[] multWares = {0,0,0,0,0};
	private String[] waresNames = {"Food","Gold","Lumber","Stone","Iron"};
	
	public Earning() {}
	
	public int getRepeatRound() {
		return repeatRound;
	}
	
	public void setRepeatRound(int repeatRound) {
		this.repeatRound = repeatRound;
	}
	
	public int getWare(int level, int index) {
		//return constantWares[index] + multWares[index] * level;
		double ln = Math.log(level);
		return constantWares[index] + (int) (multWares[index] * (ln*ln+1) * (1+level*0.1));
	}
	
	public void setEarning(int ware, int constant, int mult) {
		constantWares[ware] = constant;
		multWares[ware] = mult;
	}
	
	public int getFood(int level) {
		return getWare(level,0);
	}
	public int getGold(int level) {
		return getWare(level,1);
	}
	public int getLumber(int level) {
		return getWare(level,2);
	}
	public int getStone(int level) {
		return getWare(level,3);
	}
	public int getIron(int level) {
		return getWare(level,4);
	}
	public void setFoodEarning(int constant, int mult) {
		setEarning(0,constant, mult);
	}
	public void setGoldEarning(int constant, int mult) {
		setEarning(1,constant, mult);
	}
	public void setLumberEarning(int constant, int mult) {
		setEarning(2,constant, mult);
	}
	public void setStoneEarning(int constant, int mult) {
		setEarning(3,constant, mult);
	}
	public void setIronEarning(int constant, int mult) {
		setEarning(4,constant, mult);
	}
	
	public String toString(int level) {
		String earn = "earns: ";
		for (int i=0; i<multWares.length; i++){
			if (getWare(level,i)!=0) {
				earn += getWare(level,i)+" " + waresNames[i] +" ";
			}
		}
		if (earn.equals("earns: ")) {
			earn = "";
		} else {
			earn += " (per " + repeatRound +" rounds)";
		}
		return earn.trim();
	}
	
}
